﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CocisDAL;
using CocisModel;
using CocisModel.Common;
using System.Data;
using CocisWeb.src;

namespace CocisWeb.ManageAsset
{
    public partial class AddClusterServer : System.Web.UI.Page
    {
        public AssetDAL dal = new AssetDAL();
        public LogsDAL logs = new LogsDAL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this.BindDropDownList();
            }
        }

        public void BindDropDownList()
        {
            this.ddlNLBMode.DataSource = dal.GetNLBMode();
            this.ddlNLBMode.DataTextField = "NLBMode";
            this.ddlNLBMode.DataValueField = "NLBModeID";
            this.ddlNLBMode.DataBind();
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Asset.ClusterServerInfoDataTable dt = new Asset.ClusterServerInfoDataTable();
            Asset.ClusterServerInfoRow rows = dt.NewClusterServerInfoRow();
            Guid gd = new Guid();
            rows.ClusterID = gd;
            rows.ClusterType = this.TextBox_ClusterType.Text;
            rows.ClusterName = this.TextBox_ClusterName.Text;
            rows.ClusterIP = this.TextBox_ClusterIP.Text;
            rows.ResourceGroup = this.TextBox_ResourceGroup.Text;
            rows.NLBModeID = int.Parse(this.ddlNLBMode.SelectedValue.ToString());

            dt.Rows.Add(rows);
            dt.AcceptChanges();

            int temp = dal.AddClusterServer(dt);
            if (temp > 0)
            {
                string ip = Request.UserHostAddress.ToString();
                //int t = logs.AddNewLogsInfo("insert new ClusterServerInfo", LoginUser.User, ip);
                ClientScript.RegisterStartupScript(this.GetType(), "a", "<script language=javascript>alert('添加成功！')</script>");



            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "b", "<script language=javascript>alert('添加失败！')</script>");

            }


        }

        private object Parse(string p)
        {
            throw new NotImplementedException();
        }
    }
}